package com.oa.admin.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.oa.admin.entity.UserHoliday;
import com.oa.admin.mapper.UserHolidayMapper;
import com.oa.admin.service.IUserHolidayService;
import com.oa.admin.vo.UserHolidayListVO;
import com.oa.core.utils.DateUtil;
import com.oa.core.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Service
public class UserHolidayServiceImpl extends ServiceImpl<UserHolidayMapper, UserHoliday> implements IUserHolidayService {

    @Autowired
    private UserHolidayMapper userHolidayMapper;



    @Override
    public List<UserHolidayListVO> findUserHolidayList(String userId, Integer holidayType) {
        return userHolidayMapper.findUserHolidayList(userId, holidayType);
    }

    @Override
    public void export(String userId, Integer holidayType, HttpServletResponse response) {
        List<UserHolidayListVO> userHolidayList = userHolidayMapper.findUserHolidayList(userId, holidayType);

        String[] rows = {"编号", "假期编号", "假期名称", "定义天数", "已请天数", "假期剩余"};
        try {
            ExcelUtil.downloadExcel("个人假期列表" + DateUtil.getDayMonth(), rows, userHolidayList, "个人假期列表" + DateUtil.getDayMonth()+".xls", response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
